library Wave9 initializer init requires LegacySystem, RevelationMAIN, NightstalkersMAIN, DeltaMAIN

    globals
        private trigger ShipPathBTrigger
        private trigger ShipPathATrigger
        private trigger CivilianCasualtiesTrigger
        private trigger CivilianBoardingTrigger
        private trigger ShipResupplyTrigger
		
		private integer array           udg_Resupply
		
		private unit                    udg_NavyTransport          = null
    endglobals

    private function DayTransition takes nothing returns nothing
        local integer i = 1
        set udg_Visibility = 95
        set udg_progress = "day"
        call IntermissionRestore()
        call SetAmbientDaySound("AshenvaleDay")
        call SetSkyModel("Environment\\Sky\\BlizzardSky\\BlizzardSky.mdl")
        set udg_ZStart = 1300.0
        set udg_ZEnd = 2800.0
        call FogTransition(0.75)
        call IntermissionRestore()
        call DisableTrigger(GetTriggeringTrigger())
    endfunction

    private function Chapter1End takes nothing returns nothing
        local integer i = 1
        local rect r = Rect(-50.0,-50.0,50.0,50.0)
        local trigger t = CreateTrigger()
        call TriggerRegisterGameStateEventTimeOfDay(t,EQUAL,6.00)
        call TriggerAddAction(t,function DayTransition)
        set t = null
        if udg_Chapter!=1 then
            return
        endif
        call RemoveRect(r)
        set r = null
        
        
        call DisableTrigger(CivilianCasualtiesTrigger)
        
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Standby for Orders." )
        
        call SetImmortalSpawnEnabled(false)
        call SetCrepitusSpawnEnabled(false)
        call SetGhoulSpawnEnabled(false)

        if udg_Mode==2 then
            call GeneralText(10.0, "|cfff3ad00Major Grimes|r : Well fuck me Jesus, you're still alive! It's a good idea to consolidate in the airfield now." )
            call PolledWait(6.)
        endif
        call PolledWait(5.)
        call GeneralText(2.0, "|cffcd950cBattalion|r : We've got activity in other sectors as well. What is your situation?" )
        call PolledWait(4.)
        if udg_InitialPlayers==udg_Players then
            call GeneralText(3.5, "|cffcd950cMarine|r : Iron Hand, it's not looking too good out here. When can we expect additional support? Over." )
        else
            if udg_InitialPlayers-udg_Players==1 then
                call GeneralText(5.0, "|cffcd950cMarine|r : Iron Hand, it's not looking too good out here, and we have a man down. When can we expect additional support? Over." )
            else
                call GeneralText(5.0, "|cffcd950cMarine|r : Iron Hand, it's not looking too good out here, and we have " + I2S(udg_InitialPlayers-udg_Players) + " men down. When can we expect additional support? Over." )
            endif
        endif
        call PolledWait(8.)
        call GeneralText(3.75, "|cffcd950cBattalion|r : Fox Company will arrive in 20 minutes. In the mean time, we need you to secure the perimeter. " )
        call PolledWait(6.)
        call GeneralText(12.0, "|cffcd950cBattalion|r : JoC just informed us that Residence 41 is a cover for an old Cold War era missile silo. We will not leave it unguarded." )
        call PolledWait(2.)
        call GeneralText(6.0, "|cffcd950cMarine|r : Wilco. Out." )
        call MultiboardSetTitleText( udg_SquadStatus, "Establish a defensive perimeter in Sector E." )
        call PolledWait(6.)
        set i = udg_Sorted[1]
        call FieldChat(udg_Hero[i], 5.0, udg_Pcolors[i] + GetPlayerName(ConvertedPlayer(i)) + "|r : This whole mission is going Tango Uniform." )
        call PolledWait(4.)
        if udg_Players>1 then
            set i = udg_Sorted[2]
            call FieldChat(udg_Hero[i], 5.0, udg_Pcolors[i] + GetPlayerName(ConvertedPlayer(i)) + "|r : I hope the Good Idea Fairy doesn't give Battalion anymore stupid ideas." )
        endif
        call PolledWait(1.)
        if udg_Players>2 then
            set i = udg_Sorted[3]
            call FieldChat(udg_Hero[i], 5.0, udg_Pcolors[i] + GetPlayerName(ConvertedPlayer(i)) + "|r : Fortitudine." )
        endif
        call PolledWait(7.)
        set udg_Ghoul = 'u001'
        if udg_SquadXP>30000.0 and udg_FuelEfficiency[777]==1337 and udg_Players>5 and GetRandomInt(0,1)==1 then 
            call NightstalkersMAIN() //Nightstalkers
            return
        elseif udg_FuelEfficiency[777]==1337 then
            call GeneralText(5.0, "|cffcd950cBattalion|r : The skies are clearing.." )
            call PolledWait(8.)
            call LightningAmbience.execute()
            call PolledWait(4.5)
            call LightningAmbience.execute()
            call PolledWait(1.2)
            set udg_GlobalBoolean[1337] = false
            call SetDayNightModels( "Environment\\DNC\\DNCAshenvale\\DNCAshenvaleTerrain\\DNCAshenvaleTerrain.mdl", "Environment\\DNC\\DNCAshenvale\\DNCAshenvaleUnit\\DNCAshenvaleUnit.mdl" )
            call PolledWait(5.)
        endif
        if (udg_GlobalBoolean[1] and GetRandomInt(1,5)!=1) or GetRandomInt(1,8)==1 then
            call DeltaMAIN() //Delta
        else
            //call DestroyTrigger(gg_trg_M242_Assembly)
            //call DestroyTrigger(gg_trg_Delta_Deployment)
            //call DestroyTrigger(gg_trg_Lyganesh_Sequence)
            call RevelationMAIN() //Revelation
        endif
    endfunction
    
    private function TransportSecure takes nothing returns nothing
        local integer i = 1
		local real bonus = 0.0
        if GetTriggerUnit()==udg_NavyTransport then
            call DisableTrigger(GetTriggeringTrigger())
            call RemoveUnit(udg_NavyTransport)
            if udg_Mode==1 then
			
                call ALICEText(10.0, "USS Independence secure. |cff1e90ff25 XP|r awarded to all Marines." )
				call PolledWait(3.)
				
				if udg_CivilianRescues >= 2 then
					set bonus = I2R(udg_CivilianRescues * 5)
					if bonus > 50.0 then
						set bonus = 50.0
					endif
					call ALICEText(10.0, I2S(udg_CivilianRescues) + " civilians have been evacuated. |cff1e90ff" + I2S(R2I(bonus)) + " XP|r awarded to all Marines." )
				elseif udg_CivilianRescues == 1 then
					set bonus = 5.0
					call ALICEText(10.0, "1 civilian has been evacuated. |cff1e90ff" + I2S(R2I(bonus)) + " XP|r awarded to all Marines." )
				endif

                loop
                    exitwhen i>udg_InitialPlayers
                    if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                        set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + 25.0 + bonus
                    endif
                    set i=i+1
                endloop
				
				if udg_CivilianRescues >= 12 then
					set udg_MissionsCompleted = udg_MissionsCompleted + 1
				endif
            endif
            call PolledWait(3.)
            call LightningAmbience.execute()
            set udg_GlobalBoolean[1] = true
            call Chapter1End.execute()
        endif
    endfunction

    private function PathBConditions takes nothing returns boolean
        return GetUnitTypeId(GetTriggerUnit())=='hbot'
    endfunction

    private function PathB takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction(t,function TransportSecure)
        call DisableTrigger(GetTriggeringTrigger())
        
        // yanked from ProximitySpawnControl.j
        call GankMarine(Player(13),'nzom',2+udg_Spawn,1300,1800)
        call GankMarine(Player(14),'nzom',2+GetRandomInt(1,udg_Spawn),1500,1800)
        call GankMarine(Player(14),'ugar',GetRandomInt(0,udg_Spawn),1500,2300)
        if udg_IntenseSpawn==1 then
            call GankMarine(Player(14),'n003',GetRandomInt(1,udg_Spawn),1500,1800)
            call GankMarine(Player(13),'n00M',GetRandomInt(0,2+udg_Spawn),1500,1800)
        endif
            
        call SetProximitySpawnEnabled(false)
        call GankUnit(udg_NavyTransport,Player(14),'n00K',2+udg_Spawn,1600,2200)
        call SpawnRectRandom(gg_rct_SpawnRiverWaterfall,Player(13),'n00C',1+udg_Spawn)
        if GetRandomInt(1,2)==1 then
            call IssuePointOrder( udg_NavyTransport, "move", GetRectCenterX(gg_rct_NavyTransportExit),GetRectCenterY(gg_rct_NavyTransportExit) )
            call TriggerRegisterEnterRectSimple( t, gg_rct_NavyTransportExit )
            call SpawnRectRandom(gg_rct_NavyTransportExit,Player(14),'n00K',4+udg_Spawn)
        else
            call IssuePointOrder( udg_NavyTransport, "move", GetRectCenterX(gg_rct_NavyTransportExit2),GetRectCenterY(gg_rct_NavyTransportExit2) )
            call TriggerRegisterEnterRectSimple( t, gg_rct_NavyTransportExit2 )
            call SpawnRectRandom(gg_rct_NavyTransportExit2,Player(14),'n00K',4+udg_Spawn)
        endif
        if GetWidgetLife(udg_NavyTransport)<1000.0 then
            call GeneralText(5.0, "|cffcd950cCapt. Lawrence|r : The ship's taking heavy damage!" )
        endif
        if GetRandomInt(1,25)==1 then
            call SpawnRectRandom(gg_rct_SpawnEastCave,Player(13),'z002',1+udg_Spawn)
            call SpawnRectRandom(gg_rct_SpawnRiverWaterfall,Player(13),'n00C',1+udg_Spawn)
        else
            call SpawnRectRandom(gg_rct_SpawnEastJungle,Player(14),'u000',4+udg_Spawn)
            call SpawnRectRandom(gg_rct_SpawnEastJungle,Player(13),'n005',4+udg_Spawn)
            call SpawnRectRandom(gg_rct_SpawnNorthWaterfall,Player(14),'u005',udg_Spawn)
        endif
        if GetRandomInt(0,5)!=1 then
            call GeneralText(3.0, "|cffcd950cMarine|r : The transport's going to be fine. We need to get out of here." )
        else
            call GeneralText(3.0, "|cffcd950cMarine|r : Move to the surface and we'll pick off those Zulus behind us." )
        endif
        call PolledWait(8.)
        call GankUnit(udg_NavyTransport,Player(14),'n00K',2+udg_Spawn,1200,1500)
        set t = null
    endfunction

    private function USSIndependenceEcell takes nothing returns nothing
        local item i = GetManipulatedItem()
        local unit u = GetTriggerUnit()
        local integer id = GetItemTypeId(i)
        if id=='I00G' then
            call UnitUseItem(u,i)
        else
            call UnitRemoveItem(u,i)
        endif
        set i = null
        set u = null
    endfunction

    private function USSIndependenceFuelLeak takes nothing returns nothing
        local real x = GetRectCenterX(gg_rct_NavyPointB)
        local real y = GetRectCenterY(gg_rct_NavyPointB)
        local trigger t = CreateTrigger()
        local integer i = 1
        call GeneralText(5.0, "|cffcd950cCapt. Lawrence|r : USS Independence has run out of fuel." )
        call PolledWait(7.)
        call GeneralText(5.0, "|cffcd950cCapt. Lawrence|r : Looks like we had a pretty bad fuel leak from an earlier run in." )
        call PolledWait(4.)
        call GeneralText(5.0, "|cffcd950cCapt. Lawrence|r : We'll need a few minutes to power up our energy reactor. If you have an energy cell, that'll save us some time." )
        call UnitAddAbility(udg_NavyTransport,'A014')
        call PolledWait(6.)
        set i = udg_Sorted[1]
        call FieldChat(udg_Hero[i], 5.0, udg_Pcolors[i] + GetPlayerName(ConvertedPlayer(i)) + "|r : Spread out and give the ship some covering fire." )
        call TriggerRegisterUnitEvent(t,udg_NavyTransport,EVENT_UNIT_PICKUP_ITEM)
        call TriggerAddAction(t,function USSIndependenceEcell)
        set t = null
        loop
            exitwhen GetUnitState(udg_NavyTransport,UNIT_STATE_MANA)>98.0
            call PolledWait(5.)
        endloop 
        call GeneralText(5.0, "|cffcd950cCapt. Lawrence|r : We're powered up. Let's get out of here!" )
        call IssuePointOrder(udg_NavyTransport,"move",x,y)
        call PolledWait(5.)
        call IssuePointOrder(udg_NavyTransport,"move",x,y)
    endfunction

    private function Trig_PathA_Actions takes nothing returns nothing
        local real x = GetRectCenterX(gg_rct_NavyPointB)
        local real y = GetRectCenterY(gg_rct_NavyPointB)
        if GetUnitTypeId(GetTriggerUnit())=='hbot' then
            call DestroyTrigger(GetTriggeringTrigger())
        else
            return
        endif
        call GankUnit(udg_NavyTransport,Player(14),'n00K',2+udg_Spawn,1800,2600)
        call GankUnit(udg_NavyTransport,Player(13),'n002',2+udg_Spawn,1900,2800)
        if GetRandomInt(0,10)==1 then
            call USSIndependenceFuelLeak.execute()
            return
        endif
        call IssuePointOrder(udg_NavyTransport,"move",x,y)
        call PolledWait(2.)
        call IssuePointOrder(udg_NavyTransport,"move",x,y)
        call RandomSpawn('u00L',4,IMinBJ(5,udg_Spawn)) //Blink
        call PolledWait(5.)
        call IssuePointOrder(udg_NavyTransport,"move",x,y)
        call GankUnit(udg_NavyTransport,Player(14),'n00M',udg_Spawn,1600,1800)
        call PolledWait(5.)
        call GeneralText(1.75, "|cffcd950cMarine|r : Stay in sight." )
        call GankUnit(udg_NavyTransport,Player(14),'n00M',udg_Spawn,1500,1800)
        call PolledWait(5.)
        call LightningAmbience.execute()
        call RandomSpawn('nsw1',2,GetRandomInt(1,udg_Spawn)) //Stalker
        call SpawnRectRandom(gg_rct_SpawnRiverCave,Player(14),'n005',1+udg_Spawn)
        call GankUnit(udg_NavyTransport,Player(14),'n002',2+udg_Spawn,1500,2500)
    endfunction
    
    private function TransportDestroyed takes nothing returns nothing
        call DestroyTrigger(GetTriggeringTrigger())
        set udg_NavyTransport = null
        set udg_IntenseSpawn = 1
        call PolledWait(3.)
        call GeneralText(5.0, "USS Independence has been destroyed." )
        call PolledWait(3.)
        call StartSound(gg_snd_FattyHorde)
        call RandomSpawn('uabo',1,2) //Flesh Composite
        call RandomSpawn('z002',1,2) //Slasher
        call PolledWait(140.0*udg_Pace)
        set udg_IntenseSpawn = 0
        call Chapter1End.execute()
        call SetProximitySpawnEnabled(false)
    endfunction

    private function TransportMove takes nothing returns nothing
        local unit u
        local real x = GetRectCenterX(gg_rct_NavyPointA)
        local real y = GetRectCenterY(gg_rct_NavyPointA)
        if udg_GlobalBoolean[9] then
            return
        else
            set udg_GlobalBoolean[9]=true
        endif
        call PolledWait(40.)
        call DisableTrigger(CivilianBoardingTrigger)
        call DisableTrigger(ShipResupplyTrigger)
        if GetWidgetLife(udg_NavyTransport)>0.405 then
            call MultiboardSetTitleText( udg_SquadStatus, "Provide USS Independence with security." )
            if udg_CivilianRescues<2 then
                call GeneralText(5.0, "|cffcd950cCapt. Lawrence|r : This isn't good. We're moving out. Give us some cover." )
            else
                call GeneralText(6.0, "|cffcd950cMarine|r : We're good to go. Stay with the ship." )
            endif
            call KiloEvac(udg_NavyTransport)
            call IssuePointOrder(udg_NavyTransport,"move",x,y)
            call MBSet( udg_SquadStatus, 1, 1, "Objective : Escort Transport" )
            call QuestSetDescription(udg_CurrentOrders, "Ensure that extraction is not compromised. Provide security detail to Navy Transport. It will be taking the river route northwards. Echo Company is advised to stay in the river to narrow down routes of attack from ground Zulus. USS Independence is equipped with armanent that is effective against Zulus." )
            call ALICEText(5.0, "|cff8b864eNew Objective|r : Escort Transport." )
            call MissionUpdate.execute()
        endif
        call TriggerSleepAction(GetRandomReal(1.0,150.0))
        call StartSound(gg_snd_Loki)
        set udg_myloc = GetRandomLocInRect(udg_PlayerSpawnBoundary)
        if udg_SquadXP>30000 and udg_Players>4 then
            set u = CreateUnitAtLoc(Player(14),'U00B',udg_myloc,0) //Loki Variant B
        else
            set u = CreateUnitAtLoc(Player(14),'U002',udg_myloc,0) //Loki Variant A
        endif
        call SuspendHeroXP(u,true)
        if udg_Mode==2 then
            call GeneralText(10.0, "|cfff3ad00Major Grimes|r : Maintain your intervals! Loki deals splash damage and it hurts like a bitch." )
        endif
        set u = null
        call RemoveLocation(udg_myloc)
    endfunction

        
    private function CivilianBoarding takes nothing returns nothing
        local integer i = GetUnitPointValue(GetTriggerUnit())
        local integer id = GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))
        if RectContainsCoords(gg_rct_NavyTransportArrival,GetUnitX(udg_NavyTransport),GetUnitY(udg_NavyTransport)) and i==98 then
            call KiloEvac(udg_NavyTransport)
            call RemoveUnit(GetTriggerUnit())
            call StartSound(gg_snd_Loading)
            set udg_Experience[id] = udg_Experience[id] + 2.0

            set udg_CivilianRescues = udg_CivilianRescues + 1
            if udg_CivilianRescues==1 and GetRandomInt(0,2)==1 then
                call GeneralText(5.0, "|cffcd950cCapt. Lawrence|r : Are these people clean?" )
                call PolledWait(4.)
                call GeneralText(5.0, "|cffcd950cMarine|r : We've run them through. They're not infected." )
            elseif udg_CivilianRescues==2 then
                call TransportMove.execute()
            endif
        endif
    endfunction

    private function CivilianCasualties takes nothing returns nothing
        local integer i = GetUnitTypeId(GetTriggerUnit())
        if i=='nvlk' or i=='nvlw' or i=='nvl2' then
            set udg_CiviliansAlive = udg_CiviliansAlive - 1
            if (udg_CiviliansAlive<2 and udg_CurrentWave==9 and RectContainsCoords(gg_rct_NavyTransportArrival,GetUnitX(udg_NavyTransport),GetUnitY(udg_NavyTransport))) then
                call ALICEText(5.0, "Too many civilians have been killed." )
                call RandomSpawn('uabo',1,1) //Flesh Composite
                call TransportMove.execute()
                call DisableTrigger(GetTriggeringTrigger())
            endif
        endif
    endfunction

    private function Wave9c takes nothing returns nothing
        local unit u
        local integer i = 1
		local boolean etaspawned = false
        set udg_CurrentWave = 9
        call GenericActions.execute()
        set udg_myloc = GetRandomLocInRect(udg_PlayerSpawnBoundary)
		
		if udg_SquadXP > 80000 and udg_InitialPlayers>4 and GetRandomInt(0,5) ==1 then
			set etaspawned = true
		elseif udg_SquadXP > 45000 and udg_InitialPlayers>4 and GetRandomInt(0,10) == 1 then
			set etaspawned = true
		else
			set u = CreateUnitAtLoc(Player(14),'U00K',udg_myloc,0) //Minos
			call SuspendHeroXP(u,true)
			call RemoveLocation(udg_myloc)
			set i = GetRandomInt(1, udg_Players)
		endif
			
        call FieldChat(udg_Hero[udg_Sorted[i]], 5, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : This is a bitch and a half. Look out for anything unusual!" )
        call PolledWait(8.0*udg_Pace)
        call StartSound(udg_Ambience[1])
        call PolledWait(8.0*udg_Pace)
        call StartSound(udg_Ambience[8])
        call PolledWait(90.0*udg_Pace)
		
		if etaspawned then
			set udg_myloc = GetRandomLocInRect(udg_PlayerSpawnBoundary)
			set u = CreateUnitAtLoc(Player(14),'Uvar',udg_myloc,0) //Etaphreven A
			call SetUnitLifePercentBJ(u, 99.0 * GetRandomReal(0.7,1.0))
			call SuspendHeroXP(u,true)
			call RemoveLocation(udg_myloc)
		endif
		
        set udg_IntenseSpawn = 0
        call SetProximitySpawnEnabled(false)
        call PolledWait(30.0*udg_Pace)

        if GetRandomInt(0,45)==1 and udg_InitialPlayers>4 and etaspawned == false then
            set udg_myloc = GetRandomLocInRect(udg_PlayerSpawnBoundary)
            set u = CreateUnitAtLoc(Player(14),'Uvar',udg_myloc,0) //Etaphreven A
            call SuspendHeroXP(u,true)
            call RemoveLocation(udg_myloc)
        elseif GetRandomInt(0,15)==1 and udg_InitialPlayers>4 then
            call RandomSpawn('u00O',1,1) //Levithian
		elseif udg_SquadXP > 100000 then
			call RandomSpawn('u00O',1,1) //Levithian
        endif

        call PolledWait(40.0*udg_Pace)
        if udg_Players>0 then
            set udg_GlobalBoolean[1] = true
            call Chapter1End.execute()
        endif
        set u = null
    endfunction

    private function Wave9b takes nothing returns nothing
        local unit u
        set udg_IntenseSpawn = 1
        call SetProximitySpawnEnabled(true)
        call RandomSpawn('uabo',1,1) //Flesh Composite
        call StartSound(gg_snd_Loki)
        set udg_myloc = GetRandomLocInRect(udg_PlayerSpawnBoundary)
        set u = CreateUnitAtLoc(Player(14),'U00B',udg_myloc,0) //Loki Variant B
        call SuspendHeroXP(u, true)
        set u = null
        call RemoveLocation(udg_myloc)
        call PolledWait(140.)
        set udg_IntenseSpawn = 0
        call SetProximitySpawnEnabled(false)
        call Chapter1End.execute()
    endfunction

    private function CivEvac takes nothing returns nothing
        local location l = GetUnitLoc(udg_NavyTransport)
        local group g = AMGetUnitsInRange(500,l,Condition(function SelectGround))
        local unit u
        local integer i=1
        local integer id
        loop
            set u = FirstOfGroup(g)
            exitwhen u==null
            call GroupRemoveUnit(g,u)
            if GetUnitPointValue(u)==98 then
                set id=GetConvertedPlayerId(GetOwningPlayer(u))
                call RemoveUnit(u)
                call StartSound(gg_snd_Loading)
                set udg_Experience[id] = udg_Experience[id] + 2.0
                set udg_CivilianRescues = udg_CivilianRescues + 1
                if udg_CivilianRescues==2 then
                    call TransportMove.execute()
                endif
            endif
        endloop
        call DestroyGroup(g)
        set g = null
        call RemoveLocation(l)
        set l = null
        call TriggerRegisterEnterRectSimple( CivilianBoardingTrigger, gg_rct_NavyTransportArrival )
        call TriggerRegisterLeaveRectSimple( CivilianBoardingTrigger, gg_rct_NavyTransportArrival )
    endfunction

    private function Wave9a takes nothing returns nothing
        local trigger t = CreateTrigger()
        local real x = GetRectCenterX(gg_rct_NavyTransportArrival)
        local real y = GetRectCenterY(gg_rct_NavyTransportArrival)
        set udg_CurrentWave = 9
        call GenericActions.execute()
        if udg_CiviliansAlive<2 then
            call Wave9b.execute()
            return
        endif
        call TriggerRegisterEnterRectSimple( ShipPathATrigger, gg_rct_NavyPointA )
        call TriggerRegisterEnterRectSimple( ShipPathBTrigger, gg_rct_NavyPointB )
        call GeneralText(6.0, "|cffcd950cBattalion|r : Our vessel is arriving south of the main river. Bring the civilians to rendezvous point for extraction." )
        call PingMinimapEx(6000.0, -3700.0, 50.0, 255, 0, 0, false)
        call PolledWait(10.0)
        
        call SpawnShredder()

        call MultiboardSetTitleText( udg_SquadStatus, "Evacuate Civilians" )
        call MBSet( udg_SquadStatus, 1, 1, "Objective : Evacuate Civilians" )
        call QuestSetDescription(udg_CurrentOrders, "Bring the civilians to extraction point at the south river entrance. The USS Independence will be waiting. Minimize combat exposure, we don't want to get these civilians infected." )
        call ALICEText(5.0, "|cff8b864eNew Objective|r : Evacuate Civilians." )
        call MissionUpdate.execute()
        call PolledWait(20.0*udg_Pace)
        set udg_Visibility = 57
        call IntermissionRestore()
        set udg_ACA[12] = false
        set udg_NavyTransport = CreateUnit(Player(11),'hbot',5838.0,-4957.0,0.0)
        call RemoveGuardPosition(udg_NavyTransport)
        call TriggerSleepAction(0.)
        call IssuePointOrder(udg_NavyTransport,"move",x,y)
        call PolledWait(4.)
        call IssuePointOrder(udg_NavyTransport,"move",x,y)
        call GeneralText(6.0, "|cffcd950cBattalion|r : USS Independence has arrived and is awaiting package." )
        call PolledWait(4.)
        call LightningAmbience.execute()
        call RandomSpawn('uabo',1,GetRandomInt(0,1)) //Flesh Composite
        call StartSound(gg_snd_SatelliteImaging)
        call TriggerRegisterUnitEvent( t, udg_NavyTransport, EVENT_UNIT_DEATH )
        call TriggerAddAction( t, function TransportDestroyed )
        set t = null
        call CivEvac()
        call TriggerRegisterEnterRectSimple( ShipResupplyTrigger, gg_rct_NavyTransportArrival )
        call TriggerRegisterLeaveRectSimple( ShipResupplyTrigger, gg_rct_NavyTransportArrival )
        call RandomSpawn('n003',udg_Players,udg_Spawn) //Immortals
        call RandomSpawn('u004',1, GetRandomInt(1,2+udg_Spawn) ) //Wraith
        call RandomSpawn('nsw1',1,2+udg_Spawn) //Stalker
        call GeneralText(5.0, "|cffcd950cCapt. Lawrence|r : This is Captain James Lawrence. We're here to evacuate the civilians." )
        call PolledWait(10.0*udg_Pace)
        call SetProximitySpawnEnabled(true)
        if udg_CiviliansAlive>2 then
            call GeneralText(2.0, "|cffcd950cMarine|r : Move it! Keep those civilians moving." )
        endif
        call PolledWait(180.)
        if udg_CivilianRescues<2 then
            call TransportMove.execute()
        endif
        call PolledWait(240.)
        if udg_CurrentWave==9 then
            set udg_IntenseSpawn = 1
        endif
    endfunction

    
    private function NavyTransportResupplyConditions takes nothing returns boolean
        local player p = GetOwningPlayer(GetTriggerUnit())
        return /*
		*/ IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)==true and /*
		*/ GetPlayerController(p)==MAP_CONTROL_USER and /*
		*/ udg_Resupply[GetConvertedPlayerId(p)]==0
    endfunction

    private function NavyTransportResupply takes nothing returns nothing
        local location l 
        local integer i = 1
        local unit u = GetTriggerUnit()
        local player p = GetOwningPlayer(GetTriggerUnit())
        local integer id = GetConvertedPlayerId(p)
        set udg_Resupply[id] = 1
        loop           
            exitwhen i > 3
            call TriggerSleepAction(0.1)
            call StartSound(gg_snd_slidepull)
            if GetUnitTypeId(u)=='H000' then
                if GetPrimaryAmmoRounds(p)==0 then
                    call UnitAddAbility(u,'A044')
                endif
                set udg_mystring = "+150"
                call AddPrimaryAmmo(u, 0, 150)
                set udg_Reloading[id] = 0
                call UnitRemoveAbility(u,'A02H')
            elseif GetUnitTypeId(u)=='H005' then
                set udg_mystring = "+2"
                call AddPrimaryAmmo(u,2,0)
            else
                set udg_mystring = "+3"
                call AddPrimaryAmmo(u,3,0)
            endif
            call AddFadingTextTag(udg_mystring,GetUnitX(u),GetUnitY(u),255,220,0,200)   
            set i = i + 1
        endloop
        call DisplayTextToPlayer(p,0.0,0.0, "Ammunition Supplies Received." )
        call KiloEvac(udg_NavyTransport)
        set u = null
    endfunction

    private function init takes nothing returns nothing
        local trigger t
        local integer i
        set t = CreateTrigger()
        call TriggerAddCondition(t,Condition(function PathBConditions))
        call TriggerAddAction(t,function PathB)
        set ShipPathBTrigger = t
        
        set t = CreateTrigger()
        call TriggerAddAction(t,function Trig_PathA_Actions)
        set ShipPathATrigger = t
        
        set t = CreateTrigger()
        call TriggerAddAction(t,function CivilianBoarding)
        set CivilianBoardingTrigger = t
        
        set t = CreateTrigger()
        call TriggerAddAction(t,function CivilianCasualties)
        set CivilianCasualtiesTrigger = t
        
        set i = 1
        loop
            exitwhen i > udg_InitialPlayers
            set udg_Resupply[udg_Sorted[i]] = 0
            call TriggerRegisterPlayerUnitEvent(CivilianCasualtiesTrigger, ConvertedPlayer(udg_Sorted[i]), EVENT_PLAYER_UNIT_DEATH, null)
            set i = i + 1
        endloop
        
        set t = CreateTrigger()
        call TriggerAddCondition(t, Condition(function NavyTransportResupplyConditions) )
        call TriggerAddAction(t,function NavyTransportResupply)
        set ShipResupplyTrigger = t
        
        call RegisterFunction("Wave9a", function Wave9a)
        call RegisterFunction("Wave9b", function Wave9b)
        call RegisterFunction("Wave9c", function Wave9c)

    endfunction
    
endlibrary